package com.trip.order.controller;


import com.trip.common.dto.OrderDTO;
import com.trip.common.entity.TripOrder;
import com.trip.common.vo.Result;
import com.trip.order.producer.IRocketMQService;
import com.trip.order.service.TripOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.trip.common.dto.LocationDto;
import com.trip.common.vo.Result;
import com.trip.order.service.impl.TripOrderServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hr
 * @since 2024-09-05
 */
@RestController
@RequestMapping("/order")
public class TripOrderController {
    @Autowired
    private TripOrderService orderService;

    @Autowired
    private TripOrderServiceImpl tripOrderService;

    @Autowired
    private IRocketMQService rocketMQService;

    @PostMapping("/crateOrder")
    public Result createOrder(@Validated  @RequestBody OrderDTO orderDTO){
        return orderService.createOrder(orderDTO);
    }

    @PostMapping("/updateOrder")
    public Result updateOrder(@Validated  @RequestBody OrderDTO orderDTO){
        return orderService.updateOrder(orderDTO);
    }

    @PostMapping("/receiveOrder")
    public Result receiverOrder(OrderDTO order){
        return orderService.receiverOrder(order);
    }

    @GetMapping("/test")
    public Result test(String name) {
        rocketMQService.sendMessage("order-pool", "消息队列启动了" + name);
        return Result.ok("");
    }

    @RequestMapping("/getDriverAcceptOrder")
    public Result getDriverAcceptOrder(@RequestBody LocationDto locationDto){
        return tripOrderService.getDriverAcceptOrder(locationDto);
    }
}

